<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%String path = request.getContextPath() ;%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %> 
<!DOCTYPE html>
<html lang="zh-CN" >
<head>
<c:set var="ctx" value="${pageContext.request.contextPath}" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>添加联系人</title>
<jsp:include page="../../import.jsp" flush="true" />
</head>
<body class="iframeBody">
        <form id="prd_spl_rl_psn_form">
            <div class="fieldset1 tabel_col tabel_col_s clearFix">
                <div class="fieldBox col_50">
                    <div class="label">姓名</div>
                    <div class="field">
                        <input name="rlNm" id="rlNm" type="text" class="ui-textbox" value="" validate="{required:true,nmcharacter:true}">
                        <span class="requiredSymbol">*</span>
                    </div>
                </div>
                <div class="fieldBox col_50">
                    <div class="label">联系电话</div>
                    <div class="field">
                        <input name="tel" id="tel" type="text" class="ui-textbox" value="" validate="{required:true,mobileAndFixedPhone:true}">
                        <span class="requiredSymbol">*</span>
                    </div>
                </div>
                <div class="fieldBox col_50">
                    <div class="label">联系人类型</div>
                    <div class="field">
                        <select name="rlTypCd" id="rlTypCd" data-value=" ">
                            <option value=" ">请选择</option>
                            <c:forEach items="${rlTypCDList }" var="kv">
								 <option value="${kv.key }">${kv.value }</option>
							</c:forEach>
                        </select>
                    </div>
                </div>
                <div class="fieldBox col_50">
                    <div class="label">证件类型</div>
                    <div class="field">
                        <select name="certTypCd" id="certTypCd" data-value=" " >
                            <option value=" ">请选择</option>
                            <c:forEach items="${certTypCdList }" var="kv">
								 <option value="${kv.key }">${kv.value }</option>
							</c:forEach>
                        </select>
                    </div>
                </div>
                <div class="fieldBox col_50">
                    <div class="label">证件号</div>
                    <div class="field">
                        <input name="certNo" id="certNo" type="text" class="ui-textbox" value="" validata="{number:true}">
                    </div>
                </div>
                <div class="fieldBox col_100">
                    <div class="label">备注</div>
                    <div class="field">
                        <input name="rlRem" id="rlRem" type="text" class="ui-textbox" value="">
                    </div>
                </div>
                <div class="fieldBox col_100" style="display:none;">
		          <div class="field">
		              <input name=splId id="splId" type="text" class="ui-textbox" value="${splId}">
		              <input name=rId id="rId" type="text" class="ui-textbox" value="${rId}">
		          </div>
		        </div>
            </div>
        </form>
<script>
	$(function() {
		$("#prd_spl_rl_psn_form").ligerForm({
			validate: true
		});
		initData();
		SET_popupIframeHeight();
	});
	//定义父级调用事件
	frameElement.dialog.onOk = function () {
	     save();
	}
	frameElement.dialog.onCancel = function () {
	     frameElement.dialog.close();
	}
	function save(){
		var ligerForm = liger.get("prd_spl_rl_psn_form");
        if (!ligerForm.valid()) {
        	$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_MUST_FIX_ITEM_INFO , SQ_type: "warning" });
            return false; //验证不通过，不执行以下代码
        }
        var data = ligerForm.getData();
        var rId = $("#rId").val();
        var url = '<%=path%>/product/splRlPsn/add.do';
        if(rId != ""){
        	url = '<%=path%>/product/splRlPsn/modify.do';
        	data["id"]= rId;
        }
        //设置供应商ID
        var splId = $("#splId").val();
        data["splId"]= splId;
        var wait_dialog;
        $.ajax({
    		type: 'post',
    		dataType:'json',
    		data:data,
    		url: url,
    		beforeSend: function(){
    	          wait_dialog=$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING ,SQ_type: "waitting" });
    	     },
    		success:function(msg){
    			 wait_dialog.close();
    			 if(msg.success == 1){
    				 top.$.ligerDialog.SQalert({content: msg.info,SQ_type: "success"});
    				 parent.npSocialRlGrid.setParm("splId",splId);
    				 parent.npSocialRlGrid.reload();
    				 frameElement.dialog.close();
    			 }else{
    				 $.ligerDialog.SQalert({content:msg.info, SQ_type: "error"});
    			 }
    		}
    	});
	}
	function initData(){
		var rId = $("#rId").val();
    	if(!rId)return;
    	var _url = '<%=path%>/product/splRlPsn/getById.do';
    	$.ajax({
    		type: 'get',
    		dataType:'json',
    		data:{id:rId},
    		url: _url,
    		success:function(msg){
    			 if(msg.success == 1){
    				 setData(msg.data);//设置数据
    			 }else{
    				 $.ligerDialog.SQalert({content:msg.info, SQ_type: "error"});
    			 }
    		}
    	});
   	}
	
	//设置页面数据
    function setData(data){
    	var form = new liger.get("prd_spl_rl_psn_form");
    	form.setData({
    		rlTypCd:data.rlTypCd,
    		rlNm:data.rlNm,
    		certTypCd:data.certTypCd,
    		certNo:data.certNo,
    		tel:data.tel,
    		rlRem:data.rlRem
    	});
	};
</script>
</body>
</html>
